// mater 节点列表

import { defineComponent, PropType, toRefs } from 'vue'
import { NSpace, NTooltip, NButton, NIcon, NPopconfirm } from 'naive-ui'
import {
  DeleteOutlined,
  InfoCircleFilled,
} from '@vicons/antd'
import { useI18n } from 'vue-i18n'
import { useRouter } from 'vue-router'
import type { Router } from 'vue-router'

const props = {
  row: {
    type: Object as PropType<any>,
    required: true
  }
}

export default defineComponent({
  name: 'TableAction',
  props,
  emits: [
    'updateList',
    'reRun',
    'reStore',
    'stop',
    'suspend',
    'deleteInstance'
  ],
  setup(props, ctx) {
    const router: Router = useRouter()

    const handleDeleteInstance = () => {
      ctx.emit('deleteInstance')
    }

    return {
      handleDeleteInstance,
      ...toRefs(props)
    }
  },
  render() {
    const { t } = useI18n()
    const state = this.row?.state

    return (
      <NSpace>
        <NTooltip trigger={'hover'}>
          {{
            default: () => t('project.master.delete'),
            trigger: () => (
              <NButton
                tag='div'
                size='small'
                type='error'
                circle
                disabled={
                  (state === 1)
                }
              >
                <NPopconfirm onPositiveClick={this.handleDeleteInstance}>
                  {{
                    default: () => t('project.workflow.delete_confirm'),
                    icon: () => (
                      <NIcon>
                        <InfoCircleFilled />
                      </NIcon>
                    ),
                    trigger: () => (
                      <NIcon>
                        <DeleteOutlined />
                      </NIcon>
                    )
                  }}
                </NPopconfirm>
              </NButton>
            )
          }}
        </NTooltip>
      </NSpace>
    )
  }
})
